#!/usr/bin/env python
#-*- coding: UTF-8 -*- 

import sys
import mysql.connector
from mysql.connector import errorcode
reload(sys)
sys.setdefaultencoding("utf8")

config = {
			"user":"zyl",
			"password":"zyl",
			"host":"192.168.131.62",
			"database":"zdc",
			"charset":"utf8",
		}

#cnx = mysql.connector.connect(user="zyl",password="zyl",host="192.168.131.62",database="zdc",charset="utf8")
cnx = mysql.connector.connect(**config)

cursor = cnx.cursor()

#insert into staff(id,name,department,sex,age,moblietel,post,affiliation)values('19','高京华','总经理办公室','男','1954-3-21','13327820998','总经理','党员');
#cursor.execute("select id,name,sex,department,post from staff")
#result = cursor.fetchall()

openfile = raw_input("Input FileName:")

f =file(openfile)
data_list = []

line = f.readline()
while line:
	data_list.append(line.split(','))
	#print line,
	line = f.readline()

f.close()

db_exe = ""
insert_format = "insert into list_tineng(id,name,num,date) values('%d','%s','%d','%s');"
s_len = len(data_list)
for i in range(s_len):
	data_list[i][0] = int(data_list[i][0])
	data_list[i][2] = int(data_list[i][2])
	db_value = (data_list[i][0],data_list[i][1],data_list[i][2],data_list[i][4])
#	print db_value
#	print ("%d,%s,%d,%s,%s" %(data_list[i][0],data_list[i][1],data_list[i][2],data_list[i][3],data_list[i][4])),
	db_exe = insert_format % db_value
	print db_exe
	cursor.execute(db_exe)

cnx.commit()
cursor.close()
cnx.close()
